package cn.dhnapplets.controller;


import cn.dhnapplets.entity.BillHoresmandNu;
import cn.dhnapplets.entity.Result;
import cn.dhnapplets.service.BillService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author 邱文彬
 * @Date 2021/11/30 11:55
 * @Version 1.0
 */


@RestController
public class BillController {
    @Autowired
    private BillService billService;


    //    查看用户可交货的额度
    @ApiOperation("查看用户可交货的额度")
    @RequestMapping(value = "/getQuantityOfDelivery", method = RequestMethod.GET)
    public Result getQuantityOfDelivery(String openId, String[] category) {

        return billService.getQuantityOfDeliveryByOpenId(openId, category);
    }

    //    查看用户悬着分类后所有的同类别订单
    @ApiOperation("查看用户悬着分类后所有的同类别订单")
    @RequestMapping(value = "/getQuotaOrder", method = RequestMethod.GET)
    public Result getQuotaOrder(String openId, String[] category) {


        return billService.getQuotaOrderByOpenId(openId, category);

    }

    //    提交订单保存数据接口
    @ApiOperation("提交订单保存数据接口")
    @RequestMapping(value = "/ErrorData", method = RequestMethod.GET)
    public Result ErrorData(String openId,Integer orderId,String billOrderMerchant , String productType,double orderWeight,String productTypeAll) {

//订单支付后
        if(openId != null){
            BillHoresmandNu billHoresmand = new BillHoresmandNu();
            billHoresmand.setBillOrderMerchant(billOrderMerchant);
            billHoresmand.setOpenId(openId);
            billHoresmand.setOrderWeight(orderWeight);
            billHoresmand.setOrderId(orderId);
            billHoresmand.setProductType(productType);
            billHoresmand.setProductTypeAll(productTypeAll);
            return billService.indert(billHoresmand);
        }

        return new Result(10001,"操作失败","openId为空");
    }


    //商家根据订单查看订单详情
    @ApiOperation("商家根据订单查看订单详情")
    @RequestMapping(value = "/getAll",method = RequestMethod.GET)
    public Result getAll(@RequestParam("id") String id){
        if (id == null || id.equals(" ") || id.equals("")) {
            return new Result(0,"id为空",null);
        }
        return billService.getAll(id);
    }


}
